/*
 * ---------------------------------------------------------------------
 * Copyright (c) 2014, 2015 All Right Reserved
 * This software is developed for study and improve coding skill ...
 *
 * Project:  Excellent Coding< EC >
 *
 * Config.h
 * This file for Common software configuration interface define.
 *
 * Eamil:   epengao@126.com
 * Author:  Peter Gao
 * Version: Intial first version.
 * --------------------------------------------------------------------
 */

#ifndef EC_CONFIG_H
#define EC_CONFIG_H

#include "ecFileOP.h"
#include "ecString.h"

#define CONFIG_ASSGINV_CHAR       '='
#define CONFIG_COMMENT_CHAR       '#'
#define CONFIG_ASSGINV_STR        "="
#define CONFIG_COMMENT_STR        "#"
#define CONFIG_MAX_ITEM_COUNT     256
#define CONFIG_MAX_ITEM_LENGTH   1024

namespace ec {

typedef struct
{
    ecString m_sKey;
    ecString m_sVal;
} ecConfigItem;

class ecConfig
{
public:
    ecConfig(const EC_PCHAR pFilePath);
    virtual ~ecConfig();
    virtual EC_U32 WriteToFile();
    virtual EC_U32 GetItemCount() const;
    virtual EC_U32 GetValue(const EC_PCHAR pKey, EC_PCHAR pVal) const;
    virtual EC_U32 SetValue(const EC_PCHAR pKey, const EC_PCHAR pVal);
    virtual EC_U32 AddItem (const EC_PCHAR pKey, const EC_PCHAR pVal);
    virtual EC_U32 DeleteItem(const EC_PCHAR pKey);
    virtual ecConfigItem GetItem(EC_U32 nIndex) const;

protected:
    virtual ecString FindKey(const EC_PCHAR pStr) const;
    virtual ecString FindVal(const EC_PCHAR pStr) const;

protected:
    EC_U32          m_nCount;
    ecFileOP        m_sFileOP;
    ecConfigItem    m_pConfigItem[CONFIG_MAX_ITEM_COUNT];
};

} /* namespace ec */
#endif /* CONFIG_H */